package org.zhs.util;

import org.springframework.util.StringUtils;

import java.util.Locale;
import java.util.ResourceBundle;

public class MessageUtils {

    /***
     * 根据解析的语言和获取提示信息
     *
     * @author 飞龙
     * @param key 读取消息key值
     * @param language 消息解析语言
     * @return 解析后的消息对象
     */
    public static String getTipMessage(String key, String language) {
        String parseLanguage = language == null ? "zh_CN" : language;
        Locale aDefault = Locale.getDefault();
//        判断language是否为空
        if (!StringUtils.isEmpty(parseLanguage)){
            String[] s = parseLanguage.split("_");
            aDefault = new Locale(s[0],s[1]);
        }
        ResourceBundle resourceBundle = ResourceBundle
                .getBundle("i18n/login",aDefault);
        return resourceBundle.getString(key);
    }

}
